package com.haaphoop.concurrentlearning;

/**
 * Created by daishuli on 2018/9/7.
 */
public class ConcurrencyTest {
    private final static long count = 100000;

    public static void currencyTest() throws Exception{
        long startTime = System.currentTimeMillis();
        Thread thread = new Thread(()->{
            int a = 0;
            for (int i = 0; i < count; i++) {
                a+=5;
            }

        });
        thread.start();
        int b = 0;
        for (int i = 0; i < count; i++) {
            b--;
        }
        long endTime = System.currentTimeMillis();
        thread.join();
        System.out.println("concurrency :" + (endTime-startTime));
    }

    public static void serial() {
        long startTime = System.currentTimeMillis();
        int a = 0;
        for (int i = 0; i < count; i++) {
            a+=5;
        }
        int b = 0;
        for (int i = 0; i < count; i++) {
            b--;
        }
        long endTime = System.currentTimeMillis();
        System.out.println("serial :" + (endTime-startTime));
    }

    public static void main(String[] args) throws Exception {
        currencyTest();
        serial();
    }
}
